import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import '../../model/security_check.dart';
import '../../model/spaceX.dart';
import '../../spaces/filespace/fileSpace.dart';
import '../../spaces/movie_space/record_list.dart';

import '../report_space/report_list.dart';

import '../image_space/record_list.dart';

class SpaceXPage extends StatefulWidget {
  @override
  SpaceXPage(this.s1);
  final SpaceX s1;

  @override
  createState() => new SpaceXPageState();
}

class SpaceXPageState extends State<SpaceXPage> {
//  定义底部导航列表
  final List<BottomNavigationBarItem> bottomTabs = [
    new BottomNavigationBarItem(icon: new Icon(Icons.list), label: ('文字')),
    new BottomNavigationBarItem(icon: new Icon(Icons.image), label: ('照片')),
    new BottomNavigationBarItem(icon: new Icon(Icons.movie), label: ('视频')),
    new BottomNavigationBarItem(
        icon: new Icon(FontAwesomeIcons.file), label: ('文件')),
  ];

  Widget getBody(int i) {
    if (i == 2) return MovieListPage(widget.s1.Guid, true, 2);
    if (i == 1) return RecordListPage(widget.s1.Guid, true);
    if (i == 0) return ReportListPage(widget.s1.Guid);
    if (i == 3)
      return FileSpacePage(
        widget.s1.Guid,
        widget.s1.Title,
        true,
        ifAppbar: false,
      );
    return new Container();
  }

  final titleList = ["文字", "照片", "视频", "文件"];
  int currentIndex = 0; //当前索引
  late Widget currentPage; //当前页面

  @override
  void initState() {
    super.initState();
    currentPage = getBody(0);
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
      appBar: new AppBar(
        // title: bottomTabs[currentIndex].title,
        title: Text(widget.s1.Title),
        // leading: Icon(Icons.menu),
      ),
      bottomNavigationBar: SafeArea(
          top: true,
          child: BottomNavigationBar(
              type: BottomNavigationBarType.fixed,
              currentIndex: currentIndex,
              items: bottomTabs,
              fixedColor: Colors.blue,
              onTap: (index) {
                setState(() {
                  currentIndex = index;
                  currentPage = getBody(currentIndex);
                });
              })),
      body: SafeArea(top: true, child: currentPage),
    );
  }
}
